﻿Imports System.Data.OleDb
Public Class frmShiftManager

#Region "NotifyIcon"

    Private Sub frmShiftManager_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Try
            If Me.WindowState = FormWindowState.Minimized Then
                Me.Visible = False
                NotifyIcon.Visible = True
                NotifyIcon.ShowBalloonTip(1, "SkyCoffee", "SkyCoffee is Still Running!", ToolTipIcon.Info)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub NotifyIcon_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon.MouseDoubleClick
        Try
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
            NotifyIcon.Visible = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub mnuLaunchApplication_Click(sender As Object, e As EventArgs) Handles mnuLaunchApplication.Click
        Try
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
            NotifyIcon.Visible = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub mnuExitApplication_Click(sender As Object, e As EventArgs) Handles mnuExitApplication.Click
        Application.Exit()
    End Sub
#End Region

    Private Sub frmShiftManager_Load(sender As Object, e As EventArgs) Handles Me.Load
        'Loads frmMenu
        pnlIcons.Controls.Clear()
        pnlIcons.Controls.Add(frmMenu.pnlIcons)

        'Load ToolTips
        AdminToolTips()

        'Clears ListView before it is populated to avoid duplicate records
        lstDisplayShifts.Items.Clear()
        lstDisplayShiftStaff.Items.Clear()

        'Populates ListView from Access Database
        Try
            PopulateShiftsListFromAccess(lstDisplayShifts)
            PopulateShiftStaffListFromAccess(lstDisplayShiftStaff)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try

    End Sub

    Private Sub btnSearchClear_Click(sender As Object, e As EventArgs) Handles btnSearchClear.Click
        'Empty Search form
        txtSearchID.Text = ""
        txtSearchStartTime.Text = ""

        txtSearchID.Focus()
    End Sub

    Private Sub btnSearchClearStaff_Click(sender As Object, e As EventArgs) Handles btnSearchClearStaff.Click
        'Empty Search form
        txtSearchShiftID.Text = ""
        txtSearchShiftStaffNumber.Text = ""
        txtSearchShiftStaffFullName.Text = ""

        txtSearchShiftID.Focus()
    End Sub

    Private Sub tsbtnAdd_Click(sender As Object, e As EventArgs) Handles tsbtnAdd.Click
        frmManageShifts.Show()
        frmManageShifts.AddNewRecord()
        Me.Close()
    End Sub

    Private Sub tsbtnEdit_Click(sender As Object, e As EventArgs) Handles tsbtnEdit.Click
        frmManageShifts.Show()
        Me.Close()
    End Sub

    Private Sub tsbtnDelete_Click(sender As Object, e As EventArgs) Handles tsbtnDelete.Click
        frmManageShifts.Show()
        Me.Close()
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        If txtSearchID.Text IsNot "" And lstDisplayShifts.Items.Count > 0 Then
            lstDisplayShifts.Focus()

            For i = 0 To lstDisplayShifts.Items.Count - 1
                'Searches first column: SubItems(0)
                If lstDisplayShifts.Items(i).SubItems(0).Text = txtSearchID.Text Then
                    lstDisplayShifts.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchStartTime.Text IsNot "" And lstDisplayShifts.Items.Count > 0 Then
            lstDisplayShifts.Focus()

            For i = 0 To lstDisplayShifts.Items.Count - 1
                'Searches second column: SubItems(1)
                If lstDisplayShifts.Items(i).SubItems(1).Text = txtSearchStartTime.Text Then
                    lstDisplayShifts.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchID.Text = "" Or txtSearchStartTime.Text = "" Then
            MsgBox("Please enter some text to initiate a search.")
        End If
    End Sub

    Private Sub btnSearchStaff_Click(sender As Object, e As EventArgs) Handles btnSearchStaff.Click
        If txtSearchShiftID.Text IsNot "" And lstDisplayShiftStaff.Items.Count > 0 Then
            lstDisplayShiftStaff.Focus()

            For i = 0 To lstDisplayShiftStaff.Items.Count - 1
                'Searches first column: SubItems(0)
                If lstDisplayShiftStaff.Items(i).SubItems(0).Text = txtSearchShiftID.Text Then
                    lstDisplayShiftStaff.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchShiftStaffNumber.Text IsNot "" And lstDisplayShiftStaff.Items.Count > 0 Then
            lstDisplayShiftStaff.Focus()

            For i = 0 To lstDisplayShiftStaff.Items.Count - 1
                'Searches second column: SubItems(1)
                If lstDisplayShiftStaff.Items(i).SubItems(1).Text = txtSearchShiftStaffNumber.Text Then
                    lstDisplayShiftStaff.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchShiftStaffFullName.Text IsNot "" And lstDisplayShiftStaff.Items.Count > 0 Then
            lstDisplayShiftStaff.Focus()

            For i = 0 To lstDisplayShiftStaff.Items.Count - 1
                'Searches third column: SubItems(2)
                If lstDisplayShiftStaff.Items(i).SubItems(2).Text = txtSearchShiftStaffFullName.Text Then
                    lstDisplayShiftStaff.Items(i).Selected = True
                End If
                MsgBox("Search Completed Successfully")
            Next

        ElseIf txtSearchShiftID.Text = "" Or txtSearchShiftStaffNumber.Text = "" Or txtSearchShiftStaffFullName.Text = "" Then
            MsgBox("Please enter some text to initiate a search.")
        End If
    End Sub
End Class